from app.models import BaseModel
from app.models.userModel import User
from tools import db
from utils.enums import TextChoices


class CoursewareType(TextChoices):
    text = "1", "文本类"
    video = "2", "视频类"
    vm = "3", "虚拟机类"


class Courseware(db.Model, BaseModel):
    __tablename__ = "api_courseware"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(120), unique=True, index=True)
    describe = db.Column(db.TEXT)
    type = db.Column(db.Enum("1", "2", "3"), default="1")
    videoPath = db.Column(db.String(120))
    pdfPath = db.Column(db.String(120))
    isSystem = db.Column(db.Boolean, index=True, default=0)
    range_uuid = db.Column(db.String(40), unique=True)
    pdf_filename = db.Column(db.String(40), comment="文件名称")
    video_filename = db.Column(db.String(40), comment="视频文件名称")

    user_id = db.Column(db.Integer, db.ForeignKey(User.id))

    def to_dict(self):
        return {
            "courseware_id": self.id,
            "name": self.name,
            "type": self.type,
            "describe": self.describe,
            "pdfPath": self.pdfPath,
            "videoPath": self.videoPath,
            "range_uuid": self.range_uuid,
            "pdfname": self.pdf_filename,
            "videoname": self.video_filename
        }
